<!-- 信谊下发移库指令明细编辑弹窗 -->
<template>
  <el-dialog
    :title="isUpdate?'修改信谊下发移库指令明细':'添加信谊下发移库指令明细'"
    :visible="visible"
    width="460px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible">
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="82px">
        <el-form-item label=":" prop="pid">
          <el-input-number
            :min="0"
            v-model="form.pid"
            placeholder="请输入"
            controls-position="right"
            class="ele-fluid ele-text-left"/>
        </el-form-item>
        <el-form-item
          label="物料号:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.itemno"
            placeholder="请输入物料号"
            clearable/>
        </el-form-item>
        <el-form-item
          label="批次:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.vendorbatch"
            placeholder="请输入批次"
            clearable/>
        </el-form-item>
        <el-form-item
          label="生产日期:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.manufacturedate"
            placeholder="请输入生产日期"
            clearable/>
        </el-form-item>
        <el-form-item
          label="生产日期:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.expireddate"
            placeholder="请输入生产日期"
            clearable/>
        </el-form-item>
        <el-form-item
          label="单位:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.unit"
            placeholder="请输入单位"
            clearable/>
        </el-form-item>
        <el-form-item
          label="转换前库位:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.fromlocation"
            placeholder="请输入转换前库位"
            clearable/>
        </el-form-item>
        <el-form-item
          label="转换后库位:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.tolocation"
            placeholder="请输入转换后库位"
            clearable/>
        </el-form-item>
        <el-form-item
          label="备注:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.text"
            placeholder="请输入备注"
            clearable/>
        </el-form-item>
        <el-form-item
          label="箱型:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.boxflag"
            placeholder="请输入箱型"
            clearable/>
        </el-form-item>
        <el-form-item
          label="箱号:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.boxno"
            placeholder="请输入箱号"
            clearable/>
        </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button
        type="primary"
        @click="save"
        :loading="loading">保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'KdlSineGoodsmovementBEdit',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data() {
    return {
      // 表单数据
      form: Object.assign({}, this.data),
      // 表单验证规则
      rules: {
        pid: [
          {required: true, message: '请输入', trigger: 'blur'}
        ],
        itemno: [
          {required: true, message: '请输入物料号', trigger: 'blur'}
        ],
        vendorbatch: [
          {required: true, message: '请输入批次', trigger: 'blur'}
        ],
        manufacturedate: [
          {required: true, message: '请输入生产日期', trigger: 'blur'}
        ],
        expireddate: [
          {required: true, message: '请输入生产日期', trigger: 'blur'}
        ],
        qty: [
          {required: true, message: '请输入数量', trigger: 'blur'}
        ],
        unit: [
          {required: true, message: '请输入单位', trigger: 'blur'}
        ],
        fromlocation: [
          {required: true, message: '请输入转换前库位', trigger: 'blur'}
        ],
        tolocation: [
          {required: true, message: '请输入转换后库位', trigger: 'blur'}
        ],
        text: [
          {required: true, message: '请输入备注', trigger: 'blur'}
        ],
        boxflag: [
          {required: true, message: '请输入箱型', trigger: 'blur'}
        ],
        boxno: [
          {required: true, message: '请输入箱号', trigger: 'blur'}
        ],
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
    };
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data);
        this.isUpdate = true;
      } else {
        this.form = {};
        this.isUpdate = false;
      }
    }
  },
  methods: {
    /* 保存编辑 */
    save() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$http[this.isUpdate ? 'put' : 'post'](this.isUpdate ? '/kdlsinegoodsmovementb/edit' : '/kdlsinegoodsmovementb/add', this.form).then(res => {
            this.loading = false;
            if (res.data.code === 0) {
              this.$message.success(res.data.msg);
              if (!this.isUpdate) {
                this.form = {};
              }
              this.updateVisible(false);
              this.$emit('done');
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            this.loading = false;
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  }
}
</script>

<style scoped>
</style>
